<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>岗位管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/main.css" media="all">
</head>


<body>
<!--主体内容-->
<div class="layui-fluid" id="postframe" style="height: 590px">
    <div class="layui-row">
        <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-list layui-bg-orange" id="postjob" lay-submit
                    lay-filter="LAY-app-contlist-search">发布岗位
            </button>
        </div>

        <div class="layui-inline" style="margin-left: 35px">
            <div class="layui-input-inline">
                <input type="text" name="id" id="demoReload" placeholder="请输入岗位名称查询" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-list layui-bg-orange" data-type="reload" id="searbtn" lay-submit
                    lay-filter="LAY-app-contlist-search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>
    </div>
    <div class="layui-row">
        <table id="tableps" lay-filter="tableFilter" style="text-align: center"></table>
        <script type="text/html" id="barDemo">
            <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
        <script type="text/html" id="lookover">
            <a href="javascript:;" target="iframe_a" class="layui-btn layui-btn-normal layui-btn-xs"
               lay-event="look">查看</a>
        </script>
    </div>
</div>

<script src="../../libs/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'jquery', 'table', 'okUtils'], function () {
        var layer = layui.layer
            , table = layui.table
            , okUtils = layui.okUtils
            , $ = layui.$


        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();

        //从cookie获取企业ID
        var enterprise = JSON.parse(window.sessionStorage.getItem("enterprise"));

        //发布岗位
        $("#postjob").click(function () {
            layer.open({
                type: 2,
                title: '岗位发布',
                shadeClose: true,
                shade: 0.4,
                resize: false,
                move: false,
                offset: '0px',
                area: ['1200px', '610px'],
                content: ['enterprisePostJob.html'],
            });
        })

        //渲染
        window.ins1 = table.render({
            elem: '#tableps'
            , title: '岗位招聘数据'
            , id: "testReload"
            , url: ctx + '/ygssecs/getjobListbypriseid?priseid=' + enterprise.enterpriseid
            , size: 'lg'
            , limit: 7
            , autoSort: false
            , page: {
                limit: 7
                , layout: ['prev', 'page', 'next', 'count', 'skip']
            }
            , loading: true
            , skin: 'nob'
            , response: {
                statusCode: 200
            }
            , request: {
                pageName: 'pageNum'
                , limitName: 'pageSize'
            }
            , cols: [[
                {field: 'jobname', title: '岗位名称', fixed: 'left', unresize: true, width: 130}
                , {field: 'jobid', title: '岗位ID', unresize: true, width: 90, hide: true}
                , {field: 'educationrequirements', title: '学历要求', unresize: true, width: 120}
                , {
                    field: 'needpeople',
                    title: '需求人数',
                    hide: 0,
                    unresize: true,
                    width: 90,
                    templet: '<div>{{ d.needpeople }} 人</div>'
                }
                , {field: 'workingexperience', title: '工作经验', unresize: true, width: 90}
                , {field: 'workplace', title: '工作地点', unresize: true, width: 90}
                , {field: 'jobsalary', title: '薪资', unresize: true, width: 80}
                , {
                    field: 'typename', title: '工作类型', templet: function (d) {
                        return d.jobType ? d.jobType.typename || '' : ''
                    }, unresize: true,
                }
                , {field: 'descriptionofjob', title: '职位描述', unresize: true}
                , {field: 'jobrequirement', title: '岗位要求', unresize: true}
                , {
                    field: 'lookover',
                    title: '应聘人员',
                    templet: '#lookover',
                    width: 90,
                    unresize: true,
                    style: 'text-align: center'
                }
                , {
                    fixed: 'right',
                    title: '操作',
                    templet: '#barDemo',
                    width: 70,
                    unresize: true,
                    style: 'text-align: center'
                }
            ]]
        });

        function delinfo(jobid) {
            okUtils.ajax("/ygssecs/deleteJob?jobid=" + jobid, "post", null, true).done(function (res) {
                location.reload()
            })
        }

        function jumppage(jobid) {
            location.href = "enterpriseCandidatesStatus.html?jobid=" + jobid;
        }

        table.on("tool(tableFilter)", function (obj) {
            let info = obj.data;
            switch (obj.event) {
                case "del":
                    layer.confirm("确定要删除吗？", function () {
                        delinfo(info.jobid)
                    })
                    break;

                case "look":
                    jumppage(info.jobid)
                    break;
            }
        });

        $("body").keydown(function () {
            if (event.keyCode == "13") {//keyCode=13是回车键
                $('#searbtn').click();//换成按钮的id即可
            }
        });

        $('#searbtn').on('click', function () {
            var jobname = $('#demoReload');
            table.reload('testReload', {
                url: ctx + '/ygssecs/getjobListbyjobname?priseid=' + enterprise.enterpriseid,
                page: {curr: 1},
                where: {
                    jobname: jobname.val(),
                }
            }, 'data')
        })


    });
</script>

</body>
</html>